#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

int main() {
    int num;
    int count = 0;
    while (cin >> num) { 
        for (int n = 0;n <= num;++n)
        {
            int tmp = n;
            int add = 0;
            int powNum = 1;
            while (tmp /= 10)
            {
                ++powNum;
            }
            int pro = tmp * tmp;

            for (int i = 0; i < powNum; i++)
            {
                tmp = pro % 10;
                add = tmp * (10 ^ i);
                pro /= 10;
            }
            if (n == add)
                ++count;
        }
    }
    cout << count;
}